package cn.com.css.taxInspection.common.job.task;

import cn.com.css.taxInspection.attention.entity.AjcxCondition;
import cn.com.css.taxInspection.attention.entity.AjcxRecord;
import cn.com.css.taxInspection.attention.entity.CaseAjxxRelation;
import cn.com.css.taxInspection.attention.service.AjcxRecordService;
import cn.com.css.taxInspection.attention.service.CaseAjxxRelationService;
import cn.com.css.taxInspection.util.DateUtils;
import cn.com.css.taxInspection.util.TsBqUtils;
import org.apache.velocity.runtime.directive.Foreach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 积案生成 根据选择的案件状态生成积案
 */
@Component("jascTask")
public class JascTask {
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
	private AjcxRecordService ajcxRecordService;
	@Resource
	private CaseAjxxRelationService caseAjxxRelationService;
	public void run(String params) throws ParseException {
		logger.info("进入定时任务jascTask，根据选择的案件状态生成积案,参数为："+params);
		if(TsBqUtils.isNotNull(params)){
			AjcxCondition req = new AjcxCondition();
			req.setAjztDm(params);
			req.setAjztDms(Arrays.asList(params.split(",")));
			List<AjcxRecord>  generateJaList = ajcxRecordService.jascajcx(req);
			List<CaseAjxxRelation> inserts = new ArrayList<>();
			CaseAjxxRelation cajxx;
			for (AjcxRecord obj:generateJaList) {
					cajxx = new CaseAjxxRelation();
					String caseId = this.getJaIdBySwjgDm(obj.getAjszjgDm());
					cajxx.setCaseId(caseId);
					cajxx.setAjbh(obj.getJcajbh());
					cajxx.setNsrmc(obj.getNsrmc());
					cajxx.setNsrsbh(obj.getNsrsbh());
					cajxx.setJcks(obj.getJcbmDm());
					cajxx.setJcr(obj.getJcry());
					cajxx.setJcajxxuuid(obj.getJcajxxuuid());
					cajxx.setSlry(obj.getSlry());
					cajxx.setAjjcztDm(obj.getAjztmc());
					cajxx.setAjmc(obj.getNsrmc());
					cajxx.setLarq(obj.getLarq());
					cajxx.setZxry(obj.getZxry());
					cajxx.setAjztDm(obj.getAjjcztDm());
					cajxx.setJcksmc(obj.getJcswjg());
					inserts.add(cajxx);
			}
			caseAjxxRelationService.saveBatch(inserts);
			logger.info("定时任务jascTask完成");
		}
	}
	private String getJaIdBySwjgDm(String swjgDm){
		String jaId = "";
		switch (swjgDm){
			case "12101009000":
				jaId="1753235180390457346";
				break;
			case "12101009100":
				jaId="4A83C7C7819843A6BC439E31E864FDDB";
				break;
			case "12101009200":
				jaId="1753235137625333761";
				break;
			case "12101009300":
				jaId="1753235212262973441";
				break;
		}
		return jaId;
	}
}
